﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//額外加入
using System.Linq.Dynamic;
using System.ComponentModel;
using CCH.Entity;

namespace CCH.DAO
{
    [DataObject(true)]
    public class classificationDAO
    {
        private Entities model = new Entities();

        //取得所有資料
        public IQueryable<classification> Get_classification_AllData(int cla_sfuno)
        {
            return (from d in model.classification
                    where d.cla_sfuno == cla_sfuno && d.state == "1"
                    orderby d.cla_sfuno
                    select d);
        }

        //取得所有資料資料特定筆數資料
        public IQueryable<classification> Get_classification_AllData(int cal_sfuno,int startRowIndex, int maximumRows)
        {
            return Get_classification_AllData(cal_sfuno).Skip(startRowIndex).Take(maximumRows);
        }

        //取得總筆數
        public int Get_classification_AllData_Countint(int cla_sfuno)
        {
            return Get_classification_AllData(cla_sfuno).Count();
        }

        //取得資料內容
        public classification Get_classificaiton(int cla_no)
        {
            return (from d in model.classification where d.cla_no == cla_no select d).FirstOrDefault();
        }

        //取得名稱
        public String Get_classificaitonName(int cla_no)
        {
            var data = (from d in model.classification where d.cla_no == cla_no select d).FirstOrDefault();
            return data.cla_name.ToString();
        }

        //新增
        public void Add_classification(classification d)
        {
            model.classification.AddObject(d);
            Update();
        }

        //刪除
        public void Delete_classification(int cla_no, int peo_uid)
        {
            classification data = Get_classificaiton(cla_no);
            data.state = "2";
            data.createuid = peo_uid;
            data.createtime = DateTime.Now;
            Update();
        }

        //更新
        public void Update()
        {
            model.SaveChanges();
        }

    }
}
